package com.plian.system.controller.fr.bulletin;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.service.fr.bulletin.BulletinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;

@RestController
@RequestMapping(value = "api/bulletin")
public class BulletinController extends BaseController {
    @Autowired
    BulletinService bulletinService;

    @PostMapping(value = "/submit")
    public ObjResult submit(@RequestBody PageData pd) throws Exception {
        return bulletinService.save(pd);
    }

    @PostMapping(value = "/originReport")
    public ObjResult originReport(@RequestBody PageData pd) throws Exception {
        return bulletinService.originReport(pd);
    }
    @PostMapping(value = "/list")
    public ListResult<PageData> listpage(@RequestBody PageData pd) throws Exception {
//        return bulletinService.list(pd);
        return bulletinService.listPage(pd);
    }

    @PostMapping(value = "/treeList")
    public ListResult<PageData> treeList(@RequestBody PageData pd) throws Exception {
        return bulletinService.treeList(pd);
    }

    @PostMapping(value = "/delete")
    public ObjResult delete(@RequestBody PageData pd) throws Exception {
        return bulletinService.delete(pd);
    }

    @PostMapping(value = "/detail")
    public ObjResult detail(@RequestBody PageData pd) throws Exception {
        return bulletinService.detail(pd);
    }
    @PostMapping(value = "/uploadFile",produces="application/json;charset=UTF-8")
    public ObjResult uploadFile(MultipartHttpServletRequest request) throws Exception {
        return bulletinService.uploadFile(request);
    }

    @PostMapping(value = "/exportExcel", produces = "application/json;charset=UTF-8")
    public void exportExcel(@RequestBody PageData pd, HttpServletResponse response, OutputStream os) throws Exception {
        bulletinService.exportExcel(pd, response, os);
    }

    @PostMapping(value = "/childList")
    public ObjResult childList(@RequestBody PageData pd) throws Exception{
        return bulletinService.childList(pd);
    }

    @PostMapping(value = "/childSummary")
    public ObjResult childSummary(@RequestBody PageData pd) throws Exception{
        return bulletinService.childSummary(pd);
    }

    @PostMapping(value = "/getSummaryDetail")
    public ObjResult getSummaryDetail(@RequestBody PageData pd) throws Exception{
        return bulletinService.getSummaryDetail(pd);
    }

}
